//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.CodeDom;

namespace OpenLS.Spreadsheet.Parsing
{
    /// <summary>
    /// Summary description for UnexpectedTokenExpection.
    /// </summary>
    class UnexpectedTokenException : FormulaException
    {
        internal UnexpectedTokenException(CodeLinePragma pragma, TokenId expected, Token actual)
            : base("\n" + pragma + getMessage(expected, actual))
        {
            Pragma = pragma;
            Expected = expected;//.ToString();

            Actual = actual;
        }
        internal UnexpectedTokenException(CodeLinePragma pragma, TokenId expected, Token actual, Exception e)
            : base("\n" + pragma + getMessage(expected, actual))
        {
            Pragma = pragma;
            Expected = expected;//.ToString();
            Actual = actual;
        }


        static string getMessage(TokenId expected, Token actual)
        {
            string r = ": Unexpected token, expected = " + expected +
                ", actual = ";
            if (actual != null)
                r += actual + "(" + actual.GetType().Name + ")";
            else
                r += "end of file";
            return r;
        }
        public string VSMessage
        {
            get
            {
                return getMessage(Expected, Actual);
            }
        }
        public readonly TokenId Expected;
        public readonly CodeLinePragma Pragma;
        internal readonly Token Actual;
        public override string ToString()
        {
            string s = Pragma.ToString() + ": Unexpected token, expected = " +
                Expected + ", actual = " +
                ((Actual != null) ? (Actual.ToString()) //+ "(" + Actual.GetType().Name + ")")
                : "end of file");
            if (InnerException != null)
                s += "\n" + InnerException;
            return s;
        }
    }
}
